package gov.child.service.impl;

import gov.child.dao.AdminDao;
import gov.child.dao.impl.AdminDaoImpl;
import gov.child.entities.po.EAdmin;
import gov.child.entities.vo.Admin;
import gov.child.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @author fzh
 * @since 2017/9/16
 */
@Service("adminService")
public class AdminServiceImpl implements AdminService {

    @Autowired
    private AdminDao adminDao;

    @Override
    public Admin findByUsernameAndPassword(String username, String password) {
        EAdmin admin = null;
        try {
            admin = adminDao.findByUsernameAndPassword(username,password);
        } catch (Exception ignored) {
            // 没找到会抛异常
        }
        if (Objects.isNull(admin)) return Admin.EMPTY_ADMIN;
        return Admin.parseFrom(admin);
    }
}
